import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

public class SolutionLCP3 {
    public boolean robot(String command, int[][] obstacles, int x, int y) {
        Set<List<Integer>> set=new HashSet<>();
        int a=0,b=0;
        for (char c : command.toCharArray()) {
            if (c=='U'){
                b++;
            }else {
                a++;
            }
            set.add(Arrays.asList(a,b));
        }
        if (a==0){
            if (y%b==0){
                for (int[] obstacle : obstacles) {
                    if (obstacle[0]==0 && obstacle[1]%b==0){
                        return false;
                    }
                }
                return true;
            }
            return false;
        }
        if (b==0){
            if (x%a==0){
                for (int[] obstacle : obstacles) {
                    if (obstacle[1]==0 && obstacle[0]%a==0){
                        return false;
                    }
                }
                return true;
            }
            return false;
        }
        for (int[] obstacle : obstacles) {
            if (obstacle[0]<=x && obstacle[1]<=y){
                for (List<Integer> list : set) {
                    if ((obstacle[0]-list.get(0))%a==0 && (obstacle[1]-list.get(1))%b==0 && (obstacle[0]-list.get(0))/a==(obstacle[1]-list.get(1))/b){
                        return false;
                    }
                }
            }
        }
        for (List<Integer> list : set) {
            if ((x-list.get(0))%a==0 && (y-list.get(1))%b==0 && (x-list.get(0))/a==(y-list.get(1))/b){
                return true;
            }
        }
        return false;
    }

    public static void main(String[] args) {
        System.out.println(new SolutionLCP3().robot("URRURRR",new int[][]{{7,7},{0,5},{2,7},{8,6},{8,7},{6,5},{4,4},{0,3},{3,6}},4915,1966));
    }
}
